/**
 * Returns the only sessionfactory.
 * This class make sure session factory can only be instancialized once for the application
 * @author smaxll
 *
 */

package utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class HibernateUtil {
    private static SessionFactory sessionFactory;
    
    static{
        try{
            sessionFactory = new Configuration().configure().buildSessionFactory();
        }catch(Throwable ex){
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static SessionFactory getSessionFactory(){
        sessionFactory.openSession();
        return sessionFactory;
    }
    
    public static Session getSession(){
        return sessionFactory.openSession();
    }
    
    public static void shutdown(){
        sessionFactory.close();
    }
    
    
    
}
